package com.xpq.petserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 文件上传路径配置类
 * @author XPQ
 * @date 2022-04-01
 */
@Configuration
public class UploadFilePathConfig implements WebMvcConfigurer {
    @Autowired
    private FilePathProperties filePathProperties;


    /**
     * Add handlers to serve static resources such as images, js, and, css
     * files from specific locations under web application root, the classpath,
     * and others.
     *
     * @param registry
     * @see ResourceHandlerRegistry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(filePathProperties.getPathPattern()).addResourceLocations("file:" + filePathProperties.getFilePhysicalPath() );
    }
}
